<!--
<template>
  <div id="app">
    &lt;!&ndash; 全局加载动画 &ndash;&gt;
    <div v-if="isLoading" class="global-loading">
      <div class="loading-content">
        <i class="el-icon-loading"></i>
        <span>加载中...</span>
      </div>
    </div>

    &lt;!&ndash; 主路由视图 &ndash;&gt;
    <router-view v-show="!isLoading" />
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      isLoading: false
    }
  },
  created() {
    // 添加请求拦截器
    this.setupInterceptors()

    // 初始化用户认证状态
    this.initializeAuth()
  },
  methods: {
    initializeAuth() {
      // 检查本地存储中的token是否有效
      const token = localStorage.getItem('token')
      if (token) {
        this.$store.commit('SET_TOKEN', token)
        const username = localStorage.getItem('username') || ''
        this.$store.commit('SET_USERNAME', username)
      }
    },
    setupInterceptors() {
      // 请求拦截器 - 添加token
      this.$axios.interceptors.request.use(config => {
        this.isLoading = true

        const token = this.$store.state.token
        if (token) {
          config.headers.Authorization = `Bearer ${token}`
        }

        return config
      }, error => {
        this.isLoading = false
        return Promise.reject(error)
      })

      // 响应拦截器 - 处理错误
      this.$axios.interceptors.response.use(response => {
        this.isLoading = false
        return response
      }, error => {
        this.isLoading = false

        // 处理HTTP错误状态码
        if (error.response) {
          switch (error.response.status) {
            case 401:
              // Token过期或无效
              this.$message.error('登录已过期，请重新登录')
              this.$store.dispatch('user/logout').then(() => {
                this.$router.push('/login')
              })
              break
            case 403:
              // 无权限
              this.$message.error('您没有权限执行此操作')
              break
            case 500:
              // 服务器错误
              this.$message.error('服务器错误，请稍后再试')
              break
            default:
              this.$message.error(error.response.data.message || '请求失败')
          }
        } else {
          this.$message.error('网络错误，请检查网络连接')
        }

        return Promise.reject(error)
      })
    }
  },
  watch: {
    // 监听路由变化，用于页面切换时的加载状态
    $route() {
      this.isLoading = true
      setTimeout(() => {
        this.isLoading = false
      }, 300) // 模拟加载延迟
    }
  }
}
</script>

<style>
#app {
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  height: 100vh;
}

/* 全局加载样式 */
.global-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.7);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
}

.loading-content {
  text-align: center;
}

.loading-content i {
  font-size: 40px;
  color: #409EFF;
  margin-bottom: 10px;
  display: block;
}

.loading-content span {
  font-size: 16px;
  color: #409EFF;
}

/* 重置样式 */
body, html {
  margin: 0;
  padding: 0;
  height: 100%;
}

/* Element UI 覆盖样式 */
.el-button {
  letter-spacing: 1px;
}

/* 全局滚动条样式 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-thumb {
  background-color: #c1c1c1;
  border-radius: 3px;
}
</style>-->


<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App'
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  min-height: 100vh;
}
body{
  display: block;
  margin: 0;
}
</style>